{include file="public/head" /}
<body>
{include file="public/menu" /}
<div class="findwords commonPage">
    <div class="bg" id="bg"></div>
    <div class="box">
        <div class="subnav">
            <span>找回密码</span>
        </div>
        <div class="main">
            <!--找回密码-->
            <form action="" id="login" method="post" class="acform" onsubmit="return false;" >
                <div class="user commonInput">
                    <input type="text" placeholder="请输入手机号" name="mobile" id="tel2">
                </div>
                <div class="password commonInput" id='getpiccode'>
                    <input type="text" class="recharge-amount amount1" id="txcode" placeholder="图形验证码" />
                    <img src="{:captcha_src()}" id="code" alt="captcha" onclick="this.src='{:captcha_src()}?rnd=' + Math.random();" />
                </div>
                <div class="commonInput" id='getcode_box'>
                    <input type="text" class="recharge-amount amount1" name="mobile_code" placeholder="短信验证码" />
                    <button class='getcode' id="getcode" onclick="getCode()">获取验证码</button>
                </div>
                <div class="agree">
                    <div class="left">
                        <a href="/">返回首页</a>
                    </div>
                    <div class="right">
                        <a href="{:url('Login/index')}">继续登录</a>
                    </div>
                </div>
                <input type="submit" value="下一步" id="next"  style="margin-top:10px;">
            </form>
        </div>
    </div>
</div>
</body>
{include file="public/load_bottom" /}
<script>
    var second = 59
    $(function () {
        setBg()

        <!-- $('.mask').click(function () { -->
            <!-- $('.alert').fadeOut(300) -->
        <!-- }) -->
    })
	
	function getCode(){
		var code = $("#txcode").val();
		var mobile = $("#tel2").val();
		var phoneReg = /(^1[3|4|5|6|7|8|9]\d{9}$)|(^09\d{8}$)/;
		if(!phoneReg.test(mobile)){
			layer.msg('请输入正确的手机号');
			return false;
		}
		if(code.length != 4){
			layer.msg('请输入正确图形验证码');
			return false;
		}		settime();
		$.ajax({
			url: "{:url('Login/getpwdcode')}",
			type: "POST",
			dataType: "JSON",
			data: {mobile:mobile,code:code},
			success: function(msg){
				layer.msg(msg.info);
				if(msg.status != 1){					countdown = 0;
					$("#getcode").text('获取验证码');
				}
				return false;
			}
		})
	}
	
	var countdown=60;
	function settime(){
		var val = $("#getcode");
		if (countdown == 0) {
			val.attr('disabled',false)
			val.text("获取验证码");
			countdown = 60;
		} else {
			val.attr('disabled',true)
			val.text(countdown+"s");
			countdown--;
			setTimeout(function() {
				settime()
			},1000)
		}

	}
    function setBg() {
        var h = $(window).height()
        $('#bg').css('height',h-110)
    }
    $('#next').click(function () {
        var tel = $('#tel2')
		var txcode = $('#txcode').val()
		var mobile_code = $("input[name='mobile_code']").val()
		var phoneReg = /(^1[3|4|5|6|7|8|9]\d{9}$)|(^09\d{8}$)/;
        if(!phoneReg.test(tel.val())){
            layer.msg('请输入正确的手机号')
            tel.focus()
            return false
        }
		if(txcode == ''){
			layer.msg('请输入图形验证码');
			return false;
		}
		if(mobile_code == ''){
			layer.msg('请输入短信验证码');
			return false;
		}
		$.ajax({
			url: "{:url('Login/checkmobile')}",
			type: "post",
			dataType: "JSON",
			data:{'mobile':tel.val(),'code':mobile_code},
			success:function(msg){
				if(msg.status == 1){
					window.location.href = msg.url;
				}else{
					layer.msg(msg.info);
				}
			}
		})
    })

</script>
</html>